   
#ifndef __DESC_COMPILER_H__
#define __DESC_COMPILER_H__

#include "ds\ds_tokenizer.h"

#include "desc_compiler_info.h"

namespace dc {

enum {
   TOKEN_SYMBOL = ds::TOKEN_USER
};

using ds::TOKEN_EOF;
using ds::TOKEN_WORD;
using ds::TOKEN_STRING;
using ds::TOKEN_INT;
using ds::TOKEN_FLOAT;

struct PARSE_INFO {
   dsSTRING       source;
   int            sourceLine;
   CONTEXT *      curContext;
   TYPE_INFO *    curType;
   int            lastTypeId;

   TOKEN *        cur;

   PARSE_INFO(void)
      : curContext(NULL)
      , curType(NULL)
      , lastTypeId(-1)
      , cur(NULL)
   {}
};

class COMPILER;

struct COMPILER_ERROR_CALLBACK : ds::TOKENIZER_ERROR_CALLBACK {
   COMPILER_ERROR_CALLBACK(COMPILER * compiler, const dsSTRING & info, int line)
      : compiler(compiler), source(info), sourceLine(line)
   {}

   virtual void Error(ds::TOKENIZER_ERROR_TYPE err, int line, char ch);

   dsSTRING source;
   int sourceLine;
   COMPILER * compiler;
};

class COMPILER {
   friend struct COMPILER_ERROR_CALLBACK;
public:
   void           RegisterVarAttrib (const char * attrib) { varAttribs += toSTRID(attrib); }
   void           RegisterDescAttrib(const char * attrib) { descAttribs += toSTRID(attrib); }

   bool           Parse             (const dsSTRING & text, CONTEXT & ctxt);

private:
   bool           Parse             (PARSE_INFO & parseInfo);
   bool           ParseDescStruct   (PARSE_INFO & parseInfo);
   bool           ParseEnum         (PARSE_INFO & parseInfo);
   bool           ParseVar          (PARSE_INFO & parseInfo);
   bool           ParseState        (const dsVECTOR<ATTRIB> & attribs, PARSE_INFO & parseInfo);
   bool           ParseType         (PARSE_INFO & parseInfo);

   bool           ParseAttribs      (dsVECTOR<ATTRIB> & attribs, const dsVECTOR<dsSTRID> & knownAttribs, PARSE_INFO & parseInfo);

public:
   dsSTRING       error;

private:
   dsVECTOR<dsSTRID> varAttribs;
   dsVECTOR<dsSTRID> descAttribs;
};

}

#endif // __DESC_COMPILER_H__